import 'package:date_format/date_format.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:tree_hole/ReplyPage.dart';
import 'QuestionList.dart';

//树洞详情（各个回复头像、时间未加、树洞时间未加、图片加载延迟待解决）
// ignore: must_be_immutable
class SingleQuestionPage extends StatefulWidget {
  final String token;
  String result;
  Map value;
  SingleQuestionPage(this.value,{this.token,Key key,this.result}) : super(key: key);

  @override
  _SingleQuestionPage createState() => new _SingleQuestionPage();
}
class _SingleQuestionPage extends State<SingleQuestionPage> {
  String result1='0';
  List commentOnList;
  void initState() {
    super.initState();
    QuestionList.getCommentsOnComment(widget.token,widget.value['id']).then((value) => setState((){
      commentOnList=value;
    })).whenComplete(() {
      print("comment异步任务处理完成");
    });
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Container(
          child: Text('详情',
            style: TextStyle(
                color: Colors.black,
                letterSpacing: 5
            ),
          ),
        ),
        centerTitle:true,
        backgroundColor: Colors.white,
        //titleSpacing: 20,
        leading: IconButton(
          icon:Icon(Icons.arrow_back,color: Colors.black),
          onPressed: () {Navigator.pop(context);
          },
        ),
        actions: [
          IconButton(icon: Icon(Icons.reply,color: Colors.black87,),
            onPressed: () async {
              await Navigator.push(context, new MaterialPageRoute(builder: (context) => ReplyPage(widget.token,1,commentId: widget.value['id'],)));
              QuestionList.getCommentsOnComment(widget.token,widget.value['id']).then((value) => setState((){
                commentOnList=value;
              }));
            },
          ),
        ],
      ),
      body: Container(
        height: double.infinity,
        width: double.infinity,
        child: ListView(
          //mainAxisAlignment: MainAxisAlignment.center,
          children: [
            SizedBox(height: 10,),
            Column(
              children: [
                ListTile(
                  title: Align(alignment: Alignment.center,child: Text(
                    widget.value['question'],
                  ),),
                ),
                Padding(
                  padding: EdgeInsets.all(15),
                  child: AspectRatio(
                    aspectRatio: 13/9,
                    child:Image.asset(widget.value["picture"],fit: BoxFit.cover,) ,
                  ),
                ),
              ],
            ),
            SizedBox(width: double.infinity,
              child: Container(
                padding: EdgeInsets.all(5),
                color: Colors.white54,
                child: Text('评论',style: TextStyle(color: Colors.black)),
              ),
            ),
            commentOnList!=null?ListView.builder(
              itemCount:commentOnList.length,
              itemBuilder: (context,index1){
                return InkWell(
                  child: Column(
                    children: [
                      ListTile(
                        title:Text('匿名评论'),
                        subtitle: Text(commentOnList[index1]['content']),
                      ),
                      Row(children: [
                        Spacer(),
                        Padding(padding: EdgeInsets.only(right: 10,bottom: 10),child: Text(commentOnList[index1]['createTime']),)]),
                    ],
                  ),
                );
              },
              shrinkWrap: true,
              physics: new NeverScrollableScrollPhysics(),
            ):Text('无'),
          ],
        ),
        color: Colors.amber[50],
      ),
    );
  }
}